<template>
<div class="container__">
    <van-tabs :active="active" @change="change" :line-width="115" :sticky="true">
        <van-tab title="待学习"></van-tab>
        <van-tab title="已学习"></van-tab>
        <van-tab title="已过期"></van-tab>
    </van-tabs>
    <scroll-view :scroll-y="true" class="scrollview" @scrolltolower="scrolltolower" :upper-threshold="0" :lower-threshold="0" @scrolltoupper="scrolltoupper">
        <div class="lodding" v-if="istop">
            <van-loading type="spinner" color="#46B7FF" />
        </div>
        <div class="goitem" @click="routerTO(item.id)" v-for="(item, index) in infolist" :key="index">
            <div class="top">
                <span class="sy-cn">订单编号：{{item.id}} </span>
                <span v-show="item.course.article_type==5&&item.desc.status==0" class="status">拼课中</span>
                <span v-show="item.course.article_type==5&&item.desc.status==1" class="status">拼课成功</span>
                <span v-show="item.course.article_type==6&&item.desc.status==1" class="status">待学习</span>
                <span v-show="item.course.article_type==5&&item.desc.status==2" class="status">拼课失败</span>
                <span v-show="item.desc.status==3" class="status">已学习 </span>
                <span v-show="item.status==4" class="status">已取消 </span>
                <span v-show="item.status>4" class="status">已过期 
                    <span style="font-size:12px" v-show="item.status==6">(退款成功)</span>
                    <span style="font-size:12px" v-show="item.status==5">(退款中)</span>
                    <span style="font-size:12px" v-show="item.status==7">(退款失败)</span>
                </span>
            </div>
            <!-- 0:待付款 1：已支付 2：待定 3：已学习 4：已取消 5:退款中 6 已退款 7:拒绝退款 -->
            <div class="body">
                <div class="thumb">
                    <img :src="item.course.thumb" alt="">
                    <div class="postion">
                        <img v-show="item.course.article_type==5" :src="img+'/status1.png'" alt=""><img v-show="item.course.article_type==6" :src="img+'/status2.png'" alt=""></div>
                    </div>
                    <div class="bodyinfo">
                        <div class="title">{{item.course.title}}</div>
                        <div class="desc learnCode" v-if="active===0&&item.desc.learnning_code"><span>学习码</span>{{item.desc.learnning_code}}</div>
                        <div class="desc1 learnCode" v-else><span>学习码</span>{{item.desc.learnning_code}}</div>
                        <div class="time" v-if="item.order_type==6">开课时间：<span style="display:block">{{item.course.course_start_time}}</span></div>
                    </div>
                </div>
                <div class="footer" v-if="active===1&&item.is_evalution===0">
                    <div class="button" @click.stop="pinjiaTo(item.id)">
                        评价
                    </div>
                </div>
            </div>
            <div class="lodding" v-if="isbottom">
                <van-loading type="spinner" color="#46B7FF" />
            </div>
            <div class="lodding">{{bottomtext}}</div>
            <div v-if="nothing" class="que">
                <img :src="img+'/que/no_order@2x.png'" alt="">
             </div>
    </scroll-view>

</div>
</template>

<script>
import {
    myorder
} from '@/api/my'
export default {
    data() {
        return {
            nothing: false,
            active: 0,
            addform: {
                status: 1,
                page: 1,
            },
            infolist: [],
            Page: 1,
            lastpage: '',
            isnull: true,
            isbottom: false,
            bottomtext: '',
            istop: false,
            img:this.$URL.imgurl,
        }
    },
    methods: {
        change(e) {
            this.infolist = []
            this.isnull = true
            this.addform.page = 1
            this.bottomtext = ""
            this.active = e.target.index
            this.addform.status = e.target.index + 1
            this.getlist()
        },
        routerTO(id) {
            wx.navigateTo({
                url: '/pages/courseDetails/main?id=' + id
            })
        },
        pinjiaTo(id) {
            wx.navigateTo({
                url: '/pages/pingjia/main?id=' + id
            })
        },
        getlist() {
            this.nothing = false
            myorder(this.addform).then(res => {
                if(res.code==200){
                    this.addform.page = res.data.current_page
                    this.lastpage = res.data.last_page
                    this.infolist = this.isnull ? res.data.data : this.infolist.concat(res.data.data)
                    this.isnull = false
                }else if(res.code==201){
                   this.nothing = true
                }
                
            }).catch(err => {
                this.nothing = true
            })
        },
        scrolltolower() {
            this.bottomtext = ""
            this.isbottom = true
            setTimeout(() => {
                this.addform.page += 1
                if (this.addform.page > this.lastpage) return this.bottomtext = "我是有底线的", this.isbottom = false
                this.getlist()
                this.isbottom = false
            }, 1500)

        },

        scrolltoupper() {
            console.log('触发了')
        }
    },


    onShow() {
       
    },
    onLoad(){
        Object.assign(this.$data, this.$options.data())
        this.getlist()
    },
    onUnload() {
        this.isnull = true
         this.nothing = false
    },

}
</script>

<style lang="scss">
.container__ {
    background-color: #F4F5F5;
    min-height: 100vh;
    font-size: 16px;
    // padding: 40px 15px;
    box-sizing: border-box;

    .que {
        display: flex;
        justify-content: center;
        align-items: center;
        height: calc(100vh - 220px);

        img {
            width: 203px;
            height: 162px;
        }
    }

    .lodding {
        display: flex;
        align-items: center;
        justify-content: center;
        background-color: #fff;
        font-size: 12px;
        color: #666;
    }

    .scrollview {
        height: calc(100vh - 44px);
    }

    .van-tabs__wrap {
        box-shadow: 0px 2px 5px 0px rgba(0, 0, 0, 0.07);

    }

    .van-tabs__line {
        // width: 173px!important;
        height: 2px;
        background: rgba(70, 183, 255, 1);
        border-radius: 1px;
    }

    .goitem {
        min-height: 188px;
        background-color: #fff;
        box-sizing: border-box;
        margin-bottom: 5px;
        padding: 0 15px;

        .top {
            display: flex;
            align-items: center;
            justify-content: space-between;
            height: 42px;
            box-sizing: border-box;
            border-bottom: 1px solid #DDD;

            .sy-cn {
                font-size: 14px;
                font-weight: 500;
                color: rgba(51, 51, 51, 1);
            }

            .status {
                font-size: 15px;
                font-weight: bold;
                color: rgba(70, 183, 255, 1);
            }
        }

        .body {
            display: flex;
            padding: 9px 0 0 0;
            box-sizing: border-box;
            justify-content: space-between;

            .thumb {
                height: 110px;
                width: 154px;
                position: relative;

                .postion {
                    position: absolute;
                    left: 0;
                    width: 54px;
                    height: 15px;
                    top: 5px;

                    img {
                        width: 100%;
                        height: 100%;
                    }
                }

                img {
                    width: 100%;
                    height: 100%;
                }
            }

            .bodyinfo {
                width: 181px;
                display: flex;
                flex-direction: column;
                justify-content: space-around;

                .title {
                    max-height: 32px;
                    font-size: 14px;
                    color: #333;
                    font-weight: bold;
                    line-height: 16px;
                    overflow: hidden;
                }

                .desc {
                    color: #46B7FF;
                    font-size: 14px;

                    span {
                        width: 60px;
                        height: 20px;
                        background: rgba(234, 247, 255, 1);
                        border: 1px solid rgba(70, 183, 255, 1);
                        border-radius: 10px;
                        // color :rgba(70, 183, 255, 1);
                        margin-right: 10px;
                        padding: 0 8px;
                    }
                }

                .desc1 {
                    color: #999999;
                    font-size: 14px;

                    span {
                        width: 60px;
                        height: 20px;
                        padding: 0 8px;
                        background: rgba(244, 245, 245, 1);
                        border: 1px solid rgba(153, 153, 153, 1);
                        border-radius: 10px;
                        margin-right: 10px;
                    }
                }
                .learnCode{
                    overflow: hidden;
                    text-overflow:ellipsis;
                    white-space: nowrap;
                }
                .time {
                    font-size: 12px;
                    font-weight: 500;
                    color: rgba(233, 181, 94, 1);

                    span {
                        color: #666666;
                    }
                }
            }
        }

        .footer {
            display: flex;
            justify-content: flex-end;
            padding: 15px 0;

            .button {
                width: 80px;
                height: 30px;
                background: rgba(70, 183, 255, 1);
                border-radius: 5px;
                color: #fff;
                display: flex;
                justify-content: center;
                align-items: center;
                font-size: 14px;
            }
        }
    }
}
</style>
